//
//  ByCellServiceGoodDetailService.m
//  mijifen_ios
//
//  Created by 朱凯 on 2017/11/10.
//  Copyright © 2017年 itboye. All rights reserved.
//

#import "ByCellServiceGoodDetailService.h"

@implementation ByCellServiceGoodDetailService
{
    UIView      *_bgView;
    
    UIImageView *_mainView;             // 主图

    UILabel     *_titleLabel;           // 标题
    UILabel     *_subTitleLabel;        // 子标题
    UILabel     *_priceLabel;           // 当前价格
    UILabel     *_originPriceLabel;     // 原价

    UIView      *_addressView;          // 数量视图（可修改）
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        self.backgroundColor = [UIColor clearColor];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        [self setupUI];
    }
    return self;
}

- (void)setupUI {
    
    _bgView = [UIView new];
    _bgView.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:_bgView];
    
    // 主图
    _mainView = [[UIImageView alloc] init];
    _mainView.backgroundColor = BY_BLUE_COLOR;
    [_bgView addSubview:_mainView];
    
    // 标题
    _titleLabel = [[UILabel alloc] init];
    _titleLabel.numberOfLines = 2;
    _titleLabel.font = FONT(16);
    _titleLabel.text = @"红盖头婚庆";
    _titleLabel.textColor = [UIColor blackColor];
    _titleLabel.textAlignment = NSTextAlignmentLeft;
    [_bgView addSubview:_titleLabel];
    
    // 数量标题
    _subTitleLabel = [[UILabel alloc] init];
    _subTitleLabel.font = FONT(14);
    _subTitleLabel.textColor = [UIColor lightGrayColor];
    _subTitleLabel.textAlignment = NSTextAlignmentLeft;
    _subTitleLabel.text = @"婚礼筹办+婚礼主持(赠送一桶油)";
    [_bgView addSubview:_subTitleLabel];
    
    // 现价
    _priceLabel = [[UILabel alloc] init];
    _priceLabel.adjustsFontSizeToFitWidth = true;
    _priceLabel.font = FONT(18);
    _priceLabel.textColor = BY_RED_COLOR;
    _priceLabel.text = @"￥88888.88";
    _priceLabel.textAlignment = NSTextAlignmentLeft;
    [_bgView addSubview:_priceLabel];
    
    // 原价
    _originPriceLabel = [[UILabel alloc] init];
    _originPriceLabel.adjustsFontSizeToFitWidth = true;
    _originPriceLabel.font = FONT(14);
    _originPriceLabel.textColor = [UIColor lightGrayColor];
    _originPriceLabel.textAlignment = NSTextAlignmentLeft;
    _originPriceLabel.text = @"￥99999.99";
    [_bgView addSubview:_originPriceLabel];
    
    
    // 地址
    _addressView = [UIView new];
    _addressView.backgroundColor = BY_RED_COLOR;
    [_bgView addSubview:_addressView];
   
    // 布局
    [_bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(UIEdgeInsetsMake(0, 0, 10, 0));
    }];
    [_mainView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@10);
        make.top.equalTo(@10);
        make.bottom.equalTo(@-10);
        make.width.equalTo(_mainView.mas_height);
    }];
    [_addressView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(@-10);
        make.top.equalTo(_mainView);
        make.size.mas_equalTo(CGSizeMake(80, 30));
    }];
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_subTitleLabel);
        make.bottom.equalTo(_subTitleLabel.mas_top).offset(-5);
        make.right.equalTo(_addressView.mas_left).offset(-5);
    }];
    [_subTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(_mainView);
        make.left.equalTo(_mainView.mas_right).offset(10);
        make.right.equalTo(@-10);
    }];
    [_priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_subTitleLabel);
        make.top.equalTo(_subTitleLabel.mas_bottom).offset(5);
    }];
    [_originPriceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(_priceLabel);
        make.left.equalTo(_priceLabel.mas_right).offset(10);
    }];
    
    // 现价
    NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:_priceLabel.text];
    [attrStr addAttribute:NSFontAttributeName value:FONT(14) range:[_priceLabel.text rangeOfString:@"￥"]];
    [attrStr addAttribute:NSFontAttributeName value:FONT(14) range:NSMakeRange(_priceLabel.text.length - 2, 2)];
    _priceLabel.attributedText = attrStr;
    // 原价
    attrStr = [[NSMutableAttributedString alloc] initWithString:_originPriceLabel.text];
    [attrStr addAttribute:NSStrikethroughStyleAttributeName value:@(NSUnderlinePatternSolid|NSUnderlineStyleSingle) range:[_originPriceLabel.text rangeOfString:_originPriceLabel.text]];
    _originPriceLabel.attributedText = attrStr;
}


@end
